<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>物品列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #F5F0FF;
            margin: 0;
            padding: 0;
            text-align: center;
        }

        table {
            margin: 20px auto;
            border-collapse: collapse;
            width: 80%;
            border: 2px solid #9966FF;
        }

        th,
        td {
            border: 1px solid #9966FF;
            padding: 15px;
            text-align: center;
        }

        th {
            background-color: #8A2BE2;
            color: white;
        }

        tr:nth-child(even) {
            background-color: #F0E6FF;
        }

        tr:hover {
            background-color: #DDA0DD;
        }

        a {
            display: inline-block;
            text-decoration: none;
            color: #6A5ACD;
            padding: 8px 15px;
            border: 1px solid #6A5ACD;
            border-radius: 4px;
            transition: all 0.3s ease;
            margin: 0 5px;
        }

        a:hover {
            background-color: #6A5ACD;
            color: white;
        }

        button {
            background-color: #FF69B4;
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #FF1493;
        }
    </style>
</head>

<body>
    <h1>物品列表</h1>
    <a href="/items/add">添加物品</a>
    <a href="/logout">退出登录</a>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>描述</th>
                <th>数量</th>
                <th>类别</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <% items.forEach(function (item) { %>
            <tr>
                <td><%= item.id %></td>
                <td><%= item.name %></td>
                <td><%= item.description %></td>
                <td><%= item.quantity %></td>
                <td><%= item.category %></td>
                <td>
                    <a href="/items/edit/<%= item.id %>">编辑</a>
                    <button onclick="confirmDelete('<%= item.id %>')">删除</button>
                </td>
            </tr>
            <% }); %>
        </tbody>
    </table>
    <script>
        function confirmDelete(itemId) {
            if (confirm("确定要删除该物品吗？此操作不可撤销！")) {
                window.location.href = `/items/delete/${itemId}`;
            }
        }
    </script>
</body>

</html>